package main

import (
	"encoding/json"
	"fmt"
)

type S struct {
	Name    string
	Age     int
	Score   []int
	Address string
}

func main() {

	stu := S{
		Name:    "法师",
		Age:     12,
		Score:   []int{21, 12},
		Address: "成都",
	}

	//生成格式化json数据格式
	sli, err := json.MarshalIndent(stu, "", "	")
	//将结构体序列化为json
	//sli, err := json.Marshal(stu)
	if err != nil {
		fmt.Println("json序列化失败")
	} else {
		//将[]byte切片转换为字符串
		fmt.Println(string(sli))
	}
}
